﻿Imports DAO
Imports DTO
Public Class PhieuNhap_BUS

    Public Shared Function KiemTraQuyDinhNhapSach(ByVal sach As Sach_DTO) As Integer
        Dim sql As String = "select * from ThamSo"
        Dim thamso As DataTable = DataProvider.ExcuteReader(sql)
        Dim slnhaptoithieu As Integer = Integer.Parse(thamso.Rows(0).Item(0).ToString())
        Dim sltontoithieu As Integer = Integer.Parse(thamso.Rows(0).Item(1).ToString())
        If sach.SoLuong < slnhaptoithieu Then
            Return 0
        Else
            sql = String.Format("select SoLuong from Sach where TenSach = '{0}' and MaTheLoai = {1} and TacGia ='{2}'", sach.Ten, sach.MaTL, sach.TacGia)
            Dim obj As Object = DataProvider.ExcuteScalar(sql)
            If obj <> Nothing Then
                Dim sl As Integer = Integer.Parse(obj.ToString())
                If sl >= sltontoithieu Then
                    Return 0
                End If
            End If
        End If
        Return 1
    End Function

    Public Shared Function NhapPhieu(ByVal phieu As PhieuNhap_DTO) As Integer
        Dim flag As Integer = PhieuNhap_DAO.LapPhieu(phieu)
        Return flag
    End Function

    Public Shared Function NhapChiTiet(ByVal mapn As Integer, ByVal masach As Integer, ByVal sl As Integer)
        Dim flag As Integer = PhieuNhap_DAO.NhapChiTiet(mapn, masach, sl)
        Return flag
    End Function

    Public Shared Function LoadPhieuNhap() As DataTable
        Return PhieuNhap_DAO.LoadPhieuNhap()
    End Function

    Public Shared Function LoadPhieuNhapTheoMa(ByVal ma As Integer) As DataTable
        Return PhieuNhap_DAO.LoadPhieuNhapTheoMa(ma)
    End Function

End Class
